package space.xxhui.service

import scala.collection.mutable.HashSet
import scala.collection.mutable.Map

import org.apache.log4j.LogManager


/**
 * @author HitvzByHui
 *         date 2021-09-12
 */
object SegmentService extends Serializable {

  @transient lazy val log = LogManager.getLogger(this.getClass)

  /**
   * 将文本内容分词
   *
   * @param json
   * @return
   */
  def mapSegment(record: String): Map[String, Int] = {
    val keyCount = Map[String, Int]()
    if (record == "" || record.isEmpty()) {
      log.warn(s"record is empty: ${record}")
      keyCount
    } else {
      val wordsSet = record.split(" ").toSet
      // 进行词语统计
      val keyCount = Map[String, Int]()
      for (word <- wordsSet){
        keyCount += word -> 1
      }
      keyCount
    }
  }

}
